<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/embeds/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type"
			content="text/html; charset=iso-8859-1" />
		<title>商家列表</title>
		<script type='text/javascript' src='<c:url value='/js/jquery.simplemodal-1.3.5.min.js'/>'></script>
		<script type='text/javascript' src='<c:url value='/dwr/engine.js'/>'></script>
		<script type='text/javascript' src='<c:url value='/dwr/util.js'/>'></script>
		<script type="text/javascript" src="<c:url value='/dwr/interface/BusinessRemote.js'/>"></script>
	</head>
	<body>
		<div class="content-box">
			<!-- Start Content Box -->
			<div class="content-box-header">
				<h3>
					商家列表
				</h3>
				<div class="clear"></div>
			</div>
			<!-- End .content-box-header -->
			<form action="<c:url value='/admin/business!list.action'/>" method="post">
			<div class="content-box-content">
				<div class="tab-content default-tab" id="tab1">
					<div class="notification png_bg">
						<div>
							商家名称：
							<input type="text" name="searchName" value="${searchName }">
								商家状态： <select name="searchStatus">
									<option value="0"/>
										全部
									</option>
									<option value="1" <c:if test="${searchStatus == 1 }">selected="selected"</c:if>>
										未审核
									</option>
									<option value="2" <c:if test="${searchStatus == 2 }">selected="selected"</c:if>>
										已审核
									</option>
									<option value="3" <c:if test="${searchStatus == 3 }">selected="selected"</c:if>>
										屏蔽
									</option>
								</select>
							<input class="button" type="submit" value="查询" />
						</div>
					</div>
						<table>
							<thead>
								<tr>
									<th>
										<input class="check-all" type="checkbox" />
									</th>
									<th>
										商家名称
									</th>
									<th>
										负责人姓名
									</th>
									<th>
										产品类型
									</th>
									<th>
										所处地区
									</th>
									<th>
										状态
									</th>
									<th>
										操作
									</th>
								</tr>
							</thead>
							<tfoot>
								<tr>
									<td colspan="7">
										<div class="bulk-actions align-left">
											<select id="operChoose">
												<option value="">
													选择操作
												</option>
												<option value="del">
													删除
												</option>
												<option value="edit">
													审核
												</option>
											</select>
											<a class="button" href="javascript:void(0);" onclick="operChoose();">执行</a>
										</div>
										<div class="pagination">
											${page }
										</div>
										<!-- End .pagination -->
										<div class="clear"></div>
									</td>
								</tr>
							</tfoot>
							<tbody>
								<c:if test="${empty businessList}">
									<tr>
										<td colspan="7">
												暂无记录
										</td>
									</tr>
								</c:if>
								<c:forEach items="${businessList}" var="business">
									<tr>
										<td>
											<input type="checkbox" name="choose" value="${business.id }"/>
										</td>
										<td>
											${business.businessName }
										</td>
										<td></td>
										<td>${business.category.name }</td>
										<td>${business.location.name }</td>
										<td>
											<c:if test="${business.status == 1}">未审核</c:if>
											<c:if test="${business.status == 2}">已审核</c:if>
											<c:if test="${business.status == 3}">屏蔽</c:if>
										</td>
										<td>
											<c:if test="${business.status == 1}">
												<a href="javascript:void(0);" onclick="resetStatus(${business.id},2);">
												<img src="<c:url value='/images/admin/icons/hammer_screwdriver.png'/>"/>
												审核</a>
											</c:if>
											<c:if test="${business.status == 2}">
												<a href="javascript:void(0);" onclick="resetStatus(${business.id},3);">
												<img src="<c:url value='/images/admin/icons/cross.png'/>"/>
												屏蔽</a>
											</c:if>
											<c:if test="${business.status == 3}">
												<a href="javascript:void(0);" onclick="resetStatus(${business.id},2);">
												<img src="<c:url value='/images/admin/icons/tick_circle.png'/>"/>
												取消屏蔽</a>
											</c:if>
											<a href="<c:url value='/admin/business!initForm.action?businessPK=${business.id }'/>">
												<img src="<c:url value='/images/admin/icons/pencil.png'/>"/>
											修改</a>
											<a href="javascript:void(0);" onclick="delById(${business.id});">
											<img src="<c:url value='/images/admin/icons/cross.png'/>"/>
											删除</a>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</form>
				</div>
				<!-- End #tab1 -->
			</div>
			<!-- End .content-box-content -->
		</div>
		<!-- End .content-box -->
		<div class="clear"></div>
		<div id="sample" style="display: none; width: 200px;">
			正在操作中，请稍候...
		</div>
		<script type="text/javascript">
    	$(function(){
    		$.ajax({
    			   type: "post",
    			   url: "<c:url value='/admin/business!getOperationResult.action' />",
    			   data: null,
    			   success: function(result){
    			     	if(result == 1){
    			     		alert("操作成功!");
        			    }else if(result == -1){
        			    	alert("操作失败!");
            			}
    			   }
    			});
        });

        function delById(id){
			var oper = confirm("确定要删除此记录？");
			if(oper){
				$("#sample").modal();
				BusinessRemote.del(id, function(result){
					if(result == 1){
						alert("删除成功！");
						location.reload();
					}else if(result == -1){
						alert("删除失败，系统会跟进解决该问题！");
					}
				});
			}
        }

        function resetStatus(id, status){
			var oper = confirm("确定要要执行该操作？");
			if(oper){
				$("#sample").modal();
				BusinessRemote.updateStatus(id, status,function(result){
					if(result == 1){
						alert("操作成功！");
						location.reload();
					}else if(result == -1){
						alert("操作失败，系统会跟进解决该问题！");
					}
				});
			}
        }

        function operChoose(){
        	var operVal = $("#operChoose").val();
        	if(operVal == ""){
				alert("请选择操作类型！");
				return;
            }else if(operVal == "del"){
				batchDel();
            }else if(operVal == "edit"){
				batchResetStatus();
             }
        }

        function batchDel(){
        	var ids = getCheckboxVals();
        	if(ids == ""){
				alert("请选择要操作的目标选项！");
				return;
            }else{
            	$("#sample").modal();
				BusinessRemote.batchDel(ids, function(result){
					if(result == 1){
						alert("删除成功！");
						location.reload();
					}else if(result == -1){
						alert("删除失败，系统会跟进解决该问题！");
					}
				});
             }
        }

        function batchResetStatus(){
        	var ids = getCheckboxVals();
        	if(ids == ""){
				alert("请选择要操作的目标选项！");
				return;
            }else{
            	$("#sample").modal();
				BusinessRemote.batchUpdateStatus(ids, 2, function(result){
					if(result == 1){
						alert("审核成功！");
						location.reload();
					}else if(result == -1){
						alert("审核失败，系统会跟进解决该问题！");
					}
				});
             }
        }
    </script>
	</body>
</html>
